
//- This Source Code Form is subject to the terms of the Mozilla Public
//- License, v. 2.0. If a copy of the MPL was not distributed with this
//- file, You can obtain one at http://mozilla.org/MPL/2.0/.
//-
//- Copyright (c) 2021-present Kaleidos Ventures SL

mixin epicSwitch(name, model)
    div.check
        input.activate-input(
            id= name
            name= name
            type="checkbox"
            ng-checked= model
            ng-model= model
            ng-change="vm.updateViewOptions()"
        )
        div
        span.check-text.check-yes(translate="COMMON.YES")
        span.check-text.check-no(translate="COMMON.NO")

.epics-table.e2e-epic-table
    .epics-table-header.e2e-epics-table-header
        .name(
            translate="EPICS.TABLE.NAME"
        )
        .project(
            translate="EPICS.TABLE.PROJECT"
            ng-if="vm.options.project"
        )
        .sprint(
            translate="EPICS.TABLE.SPRINT"
            ng-if="vm.options.sprint"
        )
        .assigned(
            translate="EPICS.TABLE.ASSIGNED_TO"
            ng-if="vm.options.assigned"
        )
        .status-holder(
            translate="EPICS.TABLE.STATUS"
            ng-if="vm.options.status"
        )
        .progress(
            translate="EPICS.TABLE.PROGRESS"
            ng-if="vm.options.progress"
        )
        .epics-table-options-wrapper(
            ng-mouseleave="vm.hideEpicTableOption()"
        )
            button.epics-table-option-button.e2e-epics-column-button(ng-click="vm.displayOptions = true")
                span(translate="EPICS.TABLE.VIEW_OPTIONS")
                tg-svg(svg-icon="icon-arrow-down")
            form.epics-table-dropdown.e2e-epics-column-dropdown.ng-hide(
                ng-show="vm.displayOptions"
                ng-mouseenter="vm.keepEpicTableOption()"
            )
                .fieldset
                    label.epics-table-options-vote(
                        translate="EPICS.TABLE.PROJECT"
                        for="switch-project"
                    )
                    +epicSwitch('switch-project', 'vm.options.project')
                .fieldset
                    label.epics-table-options-vote(
                        translate="EPICS.TABLE.SPRINT"
                        for="switch-sprint"
                    )
                    +epicSwitch('switch-sprint', 'vm.options.sprint')
                .fieldset
                    label.epics-table-options-vote(
                        translate="EPICS.TABLE.ASSIGNED_TO"
                        for="switch-assigned"
                    )
                    +epicSwitch('switch-assigned', 'vm.options.assigned')
                .fieldset
                    label.epics-table-options-vote(
                        translate="EPICS.TABLE.STATUS"
                        for="switch-status"
                    )
                    +epicSwitch('switch-status', 'vm.options.status')
                .fieldset
                    label.epics-table-options-vote(
                        translate="EPICS.TABLE.PROGRESS"
                        for="switch-progress"
                    )
                    +epicSwitch('switch-progress', 'vm.options.progress')
                .fieldset
                    label.epics-table-options-vote(
                        translate="EPICS.TABLE.CLOSED_EPICS"
                        for="switch-closed"
                    )
                    +epicSwitch('switch-closed', 'vm.options.closed')
                .fieldset
                    label.epics-table-options-vote(
                        translate="EPICS.TABLE.CLOSED_US"
                        for="switch-closed_us"
                    )
                    +epicSwitch('switch-closed_us', 'vm.options.closed_us')

    .epics-table-body(
        tg-epics-sortable="vm.reorderEpic(epic, newIndex)"
        infinite-scroll="vm.nextPage()"
        infinite-scroll-disabled="vm.disabledEpicsPagination"
        infinite-scroll-immediate-check="false"
    )
        .epics-table-body-row(
            tg-repeat="epic in vm.epics track by epic.get('id')"
            tg-bind-scope
        )
            tg-epic-row.e2e-epic(
                epic="epic"
                options="vm.options"
            )

        div(tg-loading="vm.loadingEpics")
